package com.example.commen.base.dialoglib;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.commen.R;
import com.example.commen.utile.CommonUtils;


/**
 * 进度dialog,仿照IOS样式
 */
public class ProgressGifDialog extends Dialog {


    private boolean outIsHind = false;
    private String message;
    private Context context;

    private ProgressGifDialog(Context context, int theme) {
        super(context, theme);
        this.context =context;
    }

    public ProgressGifDialog(Context context, String message){
        this(context,message,false);
    }
    public ProgressGifDialog(Context context, String message, boolean outIsHind){
        this(context, R.style.Dialog_NoTitleAndBackground);
        this.message=message;
        this.outIsHind=outIsHind;
        this.context=context;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_progress_gif_dialog);
        initView();
    }

    private void initView() {
        ImageView progress =  findViewById(R.id.progressgif);
        setCancelable(true);
        this.setCanceledOnTouchOutside(outIsHind);
        //设置其大小
        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = CommonUtils.getScreenHeight();
        window.setAttributes(lp);
        RequestOptions options =new RequestOptions().placeholder(R.drawable.loading_hei);
        Glide.with(context).load(R.drawable.loading_hei).apply(options).into(progress);
    }
}
